package com.koomii.common.util.base;

import java.io.Serializable;
import java.util.List;

public class GridPager<E> implements Serializable {
    
	private static final long serialVersionUID = 5877068443418508163L;
	
    private Integer length=15;//每页条数
    private Integer currentPage=1;//当前页码
    private Integer start=0;//起始位置
    private Integer total=0;//总条数
    private Integer totalPages=0;//总页数
    private Integer end=0;//结束位置
    
    private String sortBy = "1";
    private String sortType = "desc";
    
    //起始位置 SQLServer
    private Integer begin;
    
    public GridPager(Integer currentPage,Integer length) {
        super();
        this.currentPage = currentPage;
        this.length = length;
    }
    
    public GridPager(Integer currentPage) {
        super();
        this.currentPage = currentPage;
    }
    
    public GridPager() {
        super();
    }

    /**
     * 实际数据
     */
	private List<E> rows;
    
    /**
     * 合计数据
     */
    private Object userdata;
    
    /**
     * 附加数据
     */
    private Object userdata2;
    
    /**
     * 每页条数
     * @return
     */
    public Integer getLength() {
        return length;
    }
    
    /**
     * 每页条数
     * @param length
     */
    public void setLength(Integer length) {
		if (length < 1) {
			length = 1;
		}
        this.length = length;
    }

    /**
     * 当前页页码
     * @return
     */
    public Integer getCurrentPage() {
        return currentPage;
    }

    /**
     * 当前页页码
     * @param currentPage
     */
    public void setCurrentPage(Integer currentPage) {
    	if (currentPage < 1) {
    		currentPage = 1;
		}
        this.currentPage = currentPage;
    }

    /**
     * 起始位置
     * @return
     */
    public Integer getStart() {
        if(currentPage>0){
        	start = (currentPage-1)*length;
        }
        return start;
    }

    /**
     * 总条数
     * @return
     */
    public Integer getTotal() {
        return total;
    }

    /**
     * 总条数
     * @param total
     */
    public void setTotal(Integer total) {
        this.total = total;
    }
    
    /**
     * 总页数
     * @return
     */
    public Integer getTotalPages() {
    	totalPages = this.total / this.length;
		if (this.total % this.length > 0) {
			totalPages ++;
		}
        return totalPages;
    }
    
    /**
     * 
     * @return
     */
    public String getSortBy() {
        return sortBy;
    }

    public void setSortBy(String sortBy) {
        this.sortBy = sortBy;
    }

    public String getSortType() {
        return sortType;
    }

    public void setSortType(String sortType) {
        this.sortType = sortType;
    }

	public List<E> getRows() {
		return rows;
	}
	
	/**
     * 设置List实际数据
     */
	public void setRows(List<E> rows) {
		this.rows = rows;
	}

	public Object getUserdata() {
		return userdata;
	}

	public void setUserdata(Object userdata) {
		this.userdata = userdata;
	}

	public Integer getEnd() {
		if(currentPage>0){
			end = currentPage*length;
        }
		return end;
	}

	public Integer getBegin() {
		if(currentPage>0){
			begin = (currentPage-1)*length+1;
        }
		return begin;
	}

	public Object getUserdata2() {
		return userdata2;
	}

	public void setUserdata2(Object userdata2) {
		this.userdata2 = userdata2;
	}
}
